package com.weimob.cloud.api.token.interceptor;

import com.dtflys.forest.http.ForestRequest;
import com.dtflys.forest.interceptor.Interceptor;
import com.weimob.cloud.api.token.service.WeimobTokenService;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class WeimobTokenInterceptor implements Interceptor<Object> {

    private final WeimobTokenService weimobTokenService;

    @Override
    public boolean beforeExecute(ForestRequest request) {
        // 如果 URL 需要 Token，则动态注入
        if (request.getUrl().contains("accesstoken=${accessToken}")) {
            request.replaceQuery("accesstoken", weimobTokenService.getAccessToken());
        }
        return true;
    }
}
